﻿$(document).ready(function () {
    $("#log-out").on("click", function () {
        logOut();
    });

    fetchAdminInfo();
    fetchALLParam();
});

function logOut() {
    $.ajax({
        type: "GET",
        url: "../Handle/AdminHandlerService.ashx?method=ExitLogStatus",
        dataType: "json",
        success: function (data) {
            if (0 == data.MessageType) {
                top.location = "Login.aspx";
            }
        }
    });
}

function fetchAdminInfo() {
    $.ajax({
        type: "GET",
        url: "../Handle/AdminHandlerService.ashx?method=Ad_2_Get_Admin_Info",
        dataType: "json",
        success: function (data) {
            $("#welcome-username").html("欢迎你， " + data.rows[0]["AdminName"] + "<span class='caret'></span>");
        }
    });
}
function subStrToLimitLength(str, length) {
    if (!str) { return ""; }
    return (str.length <= length) ? str : (str.substr(0, [(length - 1)]) + "...");
}

function fetchALLParam() {
    $.ajax({
        type: "GET",
        url: "../Handle/OtherHandlerService.ashx?method=Get_ALL_Param_For_JSON",
        dataType: "json",
        success: function (data) {
            // console.log(data);
            institutionAdministrator = data.rows[0]["Aname"];
            institutionFullName = data.rows[0]["Cname"];
            institutionShortName = data.rows[0]["dwjc"];
            institutionAdministrator = data.rows[0]["Xday"];

            onFolwWaitingDays = data.rows[0]["Aname"];

            membershipCapacityMinmunBookNum = data.rows[0]["MinNUM"];
            borrowMaximumBookNum = data.rows[0]["Bnum"];
            borrowMaximumDays = data.rows[0]["Lday"];

            systemStatus = data.rows[0]["Lday"];

        }
    });
}

document.addEventListener("error", function (e) {
    var elem = e.target;
    if (elem.tagName.toLowerCase() == 'img') {
        elem.src = "../images/book-default-medium.gif";
    }
}, true);